<?php
namespace Food\Controller;

class IndexController extends \Common\Controller\BaseController{

	public function index(){
		$Food=D('FoodView');
		$id = I('id');
		$sort = I('sort','time','trim');
		$_GET['sort'] = $sort;

		if ($id) {
			$map['fcid'] = $id;
		}else{
			$this->error('非法操作！');
		}

		$count  = $Food->where($map)->count();// 查询满足要求的总记录数
		$Page   = new \Com\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		if ($sort == 'time') {
			$order = "fid desc";
		}elseif ($sort == 'hot'){

		}else{

		}

		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = $Food->where($map)->limit($Page->firstRow.','.$Page->listRows)->order($order)->select();

		$cate = M('Foodcat')->where(array('fcid'=>$id))->find();

		$data = array(
			'list'  => $list,
			'page'  => $Page->show(),
			'sort'  => $sort,
			'cate'  => $cate,
		);
		$this->assign($data);
		$this->display();
	}
}